package com.tencent.compose.sample.mainpage.material3

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Slider
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import org.jetbrains.compose.ui.tooling.preview.Preview

@Preview
@Composable
internal fun SliderDemo() {
    // 用 rememberSaveable 保存滑块位置，横竖屏切换时不丢失状态
    var sliderPosition by rememberSaveable { mutableStateOf(0f) }

    Column(modifier = Modifier.padding(horizontal = 16.dp)) {
        Text(text = "当前值 ：" + sliderPosition )
        Slider(
            value = sliderPosition,
            // 滑块拖动时更新值
            onValueChange = { sliderPosition = it }
        )
    }
}